package service.impl.v2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.v2.CatVOMapper;
import model.AdVO;
import model.CatVO;
import model.GoodVO;
import service.v2.CatService;

@Service
public class CatServiceImpl implements CatService{
	@Autowired
	private CatVOMapper catVOMapper;

	public List<CatVO> getListByParent(String id) {
		return catVOMapper.getListByParent(id);	
	}

	public List<CatVO> getListAllByParent(CatVO catVO) {
		return catVOMapper.getListAllByParent(catVO) ;
	}
	
	public CatVO getCatById(String cat_id) {
		return catVOMapper.getCatById( cat_id);
	}

	public void addFirtAllCat(List<CatVO> catList) {
		CatVO cat = new CatVO();
		cat.setName("全部");
		cat.setCat_id("");
		cat.setTitle("");
		cat.setOther("");
		cat.setImg("");
		catList.add(0, cat);
	}

	public void processImg(List<CatVO> catList, String screenwidth, int i) {
		for (CatVO catVO : catList) {
			if(!"".equals(catVO.getImg())){
				catVO.setImg(catVO.getImg()+"?x-oss-process=image/resize,w_"+Integer.parseInt(screenwidth)/i);
			}
		}
	}

	/**
	 * 根据父级父级获取分类接口
	 */
	@Override
	public List<CatVO> getIndexActivityCatList(String parent_id) {
		return catVOMapper.getIndexActivityCatList(parent_id);
	}
	
	@Override
	public List<CatVO> getMemberCatList(String member_cat, String member_default_cat) {
		return catVOMapper.getMemberCatList(member_cat, member_default_cat);
	}

	@Override
	public CatVO packageShareInfo(CatVO catVO) {
		AdVO share = new AdVO();
		if(catVO.getAdList() !=null){
			if(catVO.getAdList().size()>0){
				for (int i = 0; i < catVO.getAdList().size(); i++) {
					if("2".equals(catVO.getAdList().get(i).getType())){
						share.setImage(catVO.getAdList().get(i).getImg()+"?x-oss-process=image/resize,h_100");
						share.setContent("");
						share.setTitle(catVO.getAdList().get(i).getTitle());
						share.setUrl(catVO.getAdList().get(i).getUrl());
						catVO.getAdList().get(i).setShare(share);
					}
				}
			}
		}
		return catVO;
	}

	@Override
	public List<CatVO> getCatListByGoodInfo(GoodVO goodVO) {
		return catVOMapper.getCatListByGoodInfo(goodVO);
	}
}
